map1 <- ggplot() + 
  geom_polygon(data=state, #add base map
               color = "black",
               fill="white",
               aes(x=long, y=lat, group=group)) +
  geom_point(data=minesRaw, #add mines
             aes(x=LONGITUDE, y=LATITUDE, color=CRITICAL_MINERAL,
                 text=paste("",CRITICAL_MINERAL))) +
  theme_minimal()+ #remove grey background
  theme(legend.position="none", #remove legend, axes labels/ticks
        axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank()) +
  ggtitle('"Critical Mineral" Mines & Deposits in U.S.') + #title
  coord_fixed(1.3) #adjust aspect ratio

ggplotly(map1, tooltip="text") %>% #make interactive
  style(hoverinfo="none", traces=1)

data: USGS 2017

unique(minesRaw$CRITICAL_MINERAL) %>% 
  as_tibble()

mines <- minesRaw %>% #filter to key energy transition minerals
  filter (CRITICAL_MINERAL %in% c("Aluminum",
                                  "Cadmium",
                                  "Cobalt",
                                  "Copper",
                                  "Dysprosium",
                                  "Gallium",
                                  "Indium",
                                  "Lithium",
                                  "Manganese",
                                  "Neodymium",
                                  "Nickel",
                                  "Silver",
                                  "Selenium",
                                  "Tellurium",
                                  "Rare-Earth Elements"))

map2 <- ggplot() + 
  geom_polygon(data=state, #add base map
               color = "black", 
               fill="white",
               aes(x=long, y=lat, group=group)) + 
  geom_point(data=mines, #add mines
             aes(x=LONGITUDE, y=LATITUDE, color=CRITICAL_MINERAL,
                 text=paste("",CRITICAL_MINERAL))) +
  theme_minimal()+ #remove grey background
  theme(legend.position="none", #remove legend, axes labels/ticks
        axis.title.x=element_blank(), 
        axis.text.x=element_blank(), 
        axis.ticks.x=element_blank(),
        axis.title.y=element_blank(), 
        axis.text.y=element_blank(), 
        axis.ticks.y=element_blank()) + 
  ggtitle('"Critical Mineral" Mines & Deposits in U.S.:<br>Cobalt, Gallium, Lithium, Manganese, Indium') +
  coord_fixed(1.3) #adjust aspect ratio

ggplotly(map2, tooltip="text") %>% #make interactive
  style(hoverinfo="none", traces=1)

data: USGS 2017

mines %>% #count mines by mineral
  as_tibble() %>%
  select(CRITICAL_MINERAL) %>%
  group_by(CRITICAL_MINERAL) %>%
  summarize(count=n()) %>%
  arrange(desc(count))
#TESTINGGG